//
//  XTXGongView.m
//  xiaotianxin
//
//  Created by XYC on 2019/6/20.
//  Copyright © 2019 XYC. All rights reserved.
//

#import "XTXGongView.h"
#import "XTXDengluViewController.h"
#import "XTXHomepageViewController.h"
#import "XTXHearViewController.h"
#import "XTXXiaoxiViewController.h"
#import "XTXMeViewController.h"
#import "XTXAccusationView.h"
#import "XTXBasicNavigationController.h"
#import "XTXNetworkingPageViewController.h"

static XTXGongView *tool = nil;

#define updateUserLocation @"/m/userapiv2/updateUserGeTuiCid"
@interface XTXGongView ()


@end

@implementation XTXGongView


+ (void)tianjiasuoyoudeTabdekongzhiqijiazaiEventClick
{
    dengluSet(YES);
    
    UIWindow *window = [[UIApplication sharedApplication].delegate window];
    window.frame = [UIScreen mainScreen].bounds;
    [window makeKeyAndVisible];
    
    UITabBarController *taBarController = [[UITabBarController alloc] init];
    
    XTXHomepageViewController *shiping = [[XTXHomepageViewController alloc] init];
    XTXBasicNavigationController *navShiping = [[XTXBasicNavigationController alloc] initWithRootViewController:shiping];
    
    XTXHearViewController *newhome = [[XTXHearViewController alloc] init];
    newhome.typeInt=1;
    XTXBasicNavigationController *uiGoddess = [[XTXBasicNavigationController alloc]initWithRootViewController:newhome];

    XTXMeViewController  *my = [[XTXMeViewController alloc]init];
    XTXBasicNavigationController *uimy = [[XTXBasicNavigationController alloc]initWithRootViewController:my];
    
    XTXXiaoxiViewController *msg = [[XTXXiaoxiViewController alloc] init];
    XTXBasicNavigationController *navmsg = [[XTXBasicNavigationController alloc] initWithRootViewController:msg];
    
    taBarController.viewControllers = @[uiGoddess, navShiping, navmsg, uimy];
    taBarController.tabBar.tintColor = rgbYanse1(0x7d27ff);
    taBarController.tabBar.barTintColor = [UIColor whiteColor];//NSAttributedStringKey
    [taBarController.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:rgbYanse1(0x82e0ff)} forState:UIControlStateNormal];
    [taBarController.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:rgbYanse1(0xe65974)} forState:UIControlStateSelected];
    
    window.rootViewController = taBarController;
    
}




+ (void)xieyijiemiandezhanshiEventClick
{
    XTXNetworkingPageViewController *web=[[XTXNetworkingPageViewController alloc]init];
    web.dizhiStr=xieyiUrl;
    [XTXGongTool.GetDangqiaViewController.navigationController pushViewController:web animated:YES];
}

+ (void)zanshifanhuianniubingqiezhixingfanhuianniudedianjishijianClick:(NSString *)backImgStr
{
    if (!backImgStr.length) {
        backImgStr = @"返回";
    }
    
    UIViewController *dangqianViewC = [XTXGongTool GetDangqiaViewController];
    dangqianViewC.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:backImgStr] imageWithRenderingMode:(UIImageRenderingModeAlwaysOriginal)] style:(UIBarButtonItemStylePlain) target:self action:@selector(BackEvent)];
}


- (void)zhanshijubaohelaheijiemianEventClick:(NSString *) userId withController:(UIViewController *) tempViewController
{
    UIViewController *aggregateView = XTXGongTool.GetDangqiaViewController;
    if (tempViewController) {
        aggregateView = tempViewController;
    }
    UIAlertController * accompanyAlert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    if (accompanyAlert.popoverPresentationController) {
        accompanyAlert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleAlert];
    }
    UIAlertAction *useCamera = [UIAlertAction actionWithTitle:@"举报" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        dispatch_async(dispatch_get_main_queue(), ^{
            XTXAccusationView *reportView = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(XTXAccusationView.class) owner:nil options:nil].lastObject;
            reportView.frame = CGRectMake(0, 0, pingmuKuan, pingmuGao);
            [aggregateView.view addSubview:reportView];
            NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
            parameters[@"user_id"] = userId;
            parameters[@"ruser_id"] = [[XTXGongTool share] useMode].id;
            parameters[@"content"] = @"";
            reportView.datMutDict = parameters;
        });
    }];
    
    UIAlertAction *usePhoto = [UIAlertAction actionWithTitle:@"拉黑" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
        parameters[@"user_id"] = [[XTXGongTool share] useMode].id;
        parameters[@"b_user_id"] = userId;
        [XTXNetworking networkinglaheidewangluoqingqiu:parameters.copy completionHandler:^(NSDictionary * _Nonnull dict) {
            dispatch_async(dispatch_get_main_queue(), ^{
                if ([dict[@"code"] isEqualToString:@"1"]) {
                    [aggregateView.navigationController popViewControllerAnimated:YES];
                }
                [XTXGongView showTipMsg:dict[@"msg"]];
            });
        }];
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [accompanyAlert addAction:useCamera];
    [accompanyAlert addAction:usePhoto];
    [accompanyAlert addAction:cancelAction];
    [aggregateView presentViewController:accompanyAlert animated:YES completion:nil];
}

+ (void)denglujiemiandezhanshiEventClick
{
    dispatch_async(dispatch_get_main_queue(), ^{
        if (shifouDenglu) {
            XTXDengluViewController *logViewContr = [[XTXDengluViewController alloc] init];
            logViewContr.hidesBottomBarWhenPushed = YES;
            logViewContr.navigationController.navigationBar.hidden = NO;
            [XTXGongTool.GetDangqiaViewController.navigationController pushViewController:logViewContr animated:YES];
            [self tuichuLogin];
            dengluSet(NO);
        }
    });
}

+ (void)tuichuLogin
{
    NSMutableDictionary *tempDict = [NSMutableDictionary dictionary];
    tempDict[@"id"] = XTXGongTool.share.useMode.id;
    [XTXNetworking networkingtuichudengludewangluoqingqiu:tempDict.copy completionHandler:^(NSDictionary * _Nonnull dict) {
    }];
}

+ (void)showTipMsg:(NSString *) msgStr
{
    [XTXTool showSuccess:msgStr];
}


+ (instancetype)share
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if(tool == nil)
        {
            tool = [[self alloc] init];
        }
    });
    return tool;
}

+ (id)allocWithZone:(NSZone *)zone
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (tool == nil)
        {
            tool = [super allocWithZone:zone];
        }
    });
    return tool;
}

- (id)init
{
    self = [super init];
    if (self != nil)
    {
    }
    return self;
}

- (id)copyWithZone:(NSZone *)zone
{
    return self;
}
+ (void)BackEvent
{
    UIViewController *dangqianViewC = [XTXGongTool GetDangqiaViewController];
    [dangqianViewC.navigationController popViewControllerAnimated:YES];
}
@end
